package com.itheima.mapper;

import com.itheima.domain.Orders;
import com.itheima.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersMapper {

    @Select("select * from orders")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "number",property = "number"),
            //建立与user的配置映射关系，通过user_id找到对应用户信息
            @Result(property = "user",javaType = User.class,column ="user_id",
            one = @One(select = "com.itheima.mapper.UserMapper.findById")
            ),
            //建立与items的配置映射关系，通过id找到对应商品信息
            @Result(property = "itemsList",javaType = List.class,column = "id",
                    many = @Many(select = "com.itheima.mapper.ItemsMapper.findByOid")
            )
    })
    List<Orders> findAll();

    @Select("select * from orders where user_id=#{uid}")
    @Results( {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "number",property = "number"),
            //建立与items的配置映射关系，通过id找到对应商品信息
            @Result(property = "itemsList",javaType = List.class,column = "id",
            many = @Many(select = "com.itheima.mapper.ItemsMapper.findByOid")
            )
    })
    List<Orders> findByUid(Integer uid);
}
